package com.coreJava.test02.tttt;

import org.springframework.cglib.proxy.Enhancer;
import org.springframework.cglib.proxy.MethodInterceptor;
import org.springframework.cglib.proxy.MethodProxy;

import java.lang.reflect.Method;

/**
 * 作者: LCG
 * 日期: 2019/9/4 22:19
 * 描述:
 */
public class TestMethodInterceptor<T> implements MethodInterceptor {

    private Enhancer enhancer=new Enhancer();

    public T getProxyObject(Class<T> tClass){

        enhancer.setSuperclass(tClass);
        enhancer.setCallback(this);

        return (T)enhancer.create();

    }

    @Override
    public Object intercept(Object o, Method method, Object[] objects, MethodProxy methodProxy) throws Throwable {

        System.out.println("======执行之前======");
        Object invoke = methodProxy.invokeSuper(o, objects);
        System.out.println("======执行之后======");

        return invoke;
    }
}
